package com.kexun.servlet.student;

import com.alibaba.fastjson.JSON;
import com.kexun.pojo.User;
import com.kexun.service.StuService;
import com.kexun.service.impl.StuServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/ServletScore")
public class ServletScore extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        // 查询当前用户的成绩
        //参数
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String StuNum = user.getUserNum();
        //业务逻辑

        String pageStr = request.getParameter("page");//默认查询第一页
        String limitStr = request.getParameter("limit");//默认查询10条数据
        int page = Integer.parseInt(pageStr);
        int limit = Integer.parseInt(limitStr);

        StuService ss = new StuServiceImpl();
        Map<String,Object> map = ss.findScore(StuNum,page,limit);
        String s = JSON.toJSONString(map);
        response.getWriter().print(s);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
